<%@page import="com.kaishengit.entity.CarItem"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>购物车</title>
    
  </head>
  
  <body>
  	<h3>购物车</h3>
    <table width="70%" border="1">
    		<tr>
    			<th>商品名称</th>
    			<th>价格</th>
    			<th>数量</th>
    			<th>总价</th>
    			<th>&nbsp;</th>
    		</tr>
    		<%
    			List<CarItem> shopcar = (List<CarItem>)session.getAttribute("shopcar");
    			float total = 0f;
    			if(shopcar != null){
    				for(CarItem item : shopcar){
    					total += item.getTotal();
    		%>
    		<tr>
    			<td><%=item.getProduct().getProdName() %></td>
    			<td><%=item.getProduct().getPrice() %></td>
    			<td>
    				<input type="text" value="<%=item.getNum() %>" class="changeNum"  rel="<%=item.getProduct().getId() %>"/>
    			</td>
    			<td><%=item.getTotal() %></td>
    			<td>
    				<a href="product.jspx?task=removeitem&id=<%=item.getProduct().getId()%>">删除</a>
    			</td>
    		</tr>
    		<%}} %>
    		<tr>
    			<td colspan="5" align="right">金额总计：￥<%=total %></td>
    		</tr>
    </table>
    <input type="button" value="结算" class="pay"/>
    
    <script type="text/javascript" src="script/jquery.js"></script>
 	<script type="text/javascript">
    	$(document).ready(function(){
    		$(".changeNum").change(function(){
    			
    			var num = $(this).val();
    			var id = $(this).attr("rel");
    			
    			window.location.href="product.jspx?task=changenum&id="+id+"&num="+num;
    			
    		});
    		$(".pay").click(function(){
    			
    			window.location.href="product.jspx?task=order";
    			
    		});
    		
    	});
    </script>
  </body>
  
</html>
